import { downloadByUrl, getNameByOwnUrl } from '@/utils/util'
import { TwoDateVerifyCanEqual } from '@/utils/validator'
import { Empty, FormInstance, Typography } from 'antd'

export const useFormReply = (): IItemArray[] => {
  return [
    {
      label: 'QC人员',
      name: 'qualityInspector',
      type: 'Input',
      rules: [
        {
          required: true,
          message: '请输入QC人员',
        },
      ],
    },
    {
      name: 'replyQualityTime',
      label: '回复QC时间',
      type: 'DatePicker',
      placeholder: '请选择回复QC时间',
      rules: [
        {
          required: true,
          message: '请选择回复QC时间',
        },
      ],
    },
  ]
}
export const useFormRun = (): IItemArray[] => {
  return [
    {
      name: 'actualQualityTime',
      label: '实际QC时间',
      type: 'DatePicker',
      placeholder: '请选择实际QC时间',
      rules: [
        {
          required: true,
          message: '请选择实际QC时间',
        },
      ],
    },
    {
      name: 'passed',
      label: '是否通过',
      type: 'Radio',
      option: [
        { label: '是', value: 1 },
        { label: '否', value: 0 },
      ],
    },
    {
      name: 'remark',
      label: '备注',
      type: 'TextArea',
      placeholder: '请输入备注',
      config: {
        showCount: true,
        maxLength: 100,
      },
    },
    {
      name: 'fileId',
      label: 'QC报告',
      type: 'UploadFile',
      config: {
        showCount: true,
        maxLength: 100,
      },
    },
  ]
}
export const useReplyForm = ({
  SupplierOption,
  handleSearchSupplier,
  statusFlag,
  FormReply,
  handleReplySupplierChange,
  colorOptions,
}: {
  SupplierOption: IOptionItem[]
  handleSearchSupplier: (val: string) => void
  statusFlag: boolean
  FormReply: FormInstance<any>
  handleReplySupplierChange: (val: any, items: any) => void
  colorOptions: IOptionItem[]
}): IItemArray[] => {
  return [
    // {
    //   name: 'replyStatus',
    //   label: '供应链回复状态',
    //   type: 'Radio',
    //   option: [
    //     { label: '已回复', value: 0 },
    //     { label: '已驳回', value: 1 },
    //   ],
    //   rules: [{ required: true, message: '请选择供应链回复状态' }],
    // },
    {
      name: 'replySupplierId',
      label: '供应链回复供应商',
      type: 'Select',
      option: SupplierOption,
      config: {
        suffixIcon: null,
        showSearch: true,
        optionFilterProp: 'label',
        filterOption: false,
        onSearch: handleSearchSupplier,
        onChange: handleReplySupplierChange,
        notFoundContent: <Empty description="请输入内容搜索" image={Empty.PRESENTED_IMAGE_SIMPLE} />,
      },
      rules: [{ required: statusFlag, message: '请选择供应链回复供应商' }],
      hidden: !statusFlag,
    },
    {
      name: 'replyDeliveryTime',
      label: '供应链回复发货日期',
      type: 'DatePicker',
      placeholder: '请选择供应链回复发货日期',
      rules: [
        {
          required: true,
          message: '请选择供应链回复发货日期',
        },
        ({ getFieldValue }: any) => ({
          validator: (_: any, value: any) =>
            TwoDateVerifyCanEqual(
              _,
              value,
              getFieldValue('replyDeliveryTime'),
              getFieldValue('requiredArrivalTime'),
              '供应链回复发货日期不能晚于供应链回复到仓日期',
            ),
        }),
      ],
      hidden: !statusFlag,
    },
    {
      name: 'requiredArrivalTime',
      label: '供应链回复到仓日期',
      type: 'DatePicker',
      placeholder: '请选择供应链回复到仓日期',
      rules: [
        {
          required: true,
          message: '请选择供应链回复到仓日期',
        },
        ({ getFieldValue }: any) => ({
          validator: (_: any, value: any) =>
            TwoDateVerifyCanEqual(
              _,
              value,
              getFieldValue('replyDeliveryTime'),
              getFieldValue('requiredArrivalTime'),
              '供应链回复到仓日期不能早于供应链回复发货日期',
            ),
        }),
      ],
      hidden: !statusFlag,
    },
    {
      name: 'replyRemark',
      label: !statusFlag ? '驳回备注' : '回复备注',
      type: 'TextArea',
      placeholder: statusFlag ? '无法下单、供应商、交期、价格与企划意向不一致时，请备注原因' : '请输入驳回备注',
      rules: [
        {
          required: true,
          message: '请输入' + (!statusFlag ? '驳回备注' : '回复备注'),
        },
      ],
    },
  ]
}
